package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbAddressMapper;
import com.dongdongshop.pojo.TbAddress;
import com.dongdongshop.pojo.TbAddressExample;
import com.dongdongshop.service.AddressService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DubboService
public class AddressServiceImpl implements AddressService {
    @Resource
    private TbAddressMapper tbAddressMapper;

    @Override
    public List<TbAddress> selectAddressByUserId(String userName) {
        TbAddressExample example = new TbAddressExample();
        TbAddressExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(userName);
        List<TbAddress> addressList = tbAddressMapper.selectByExample(example);
        return addressList;
    }

    @Override
    public int addAddress(TbAddress address) {
        return tbAddressMapper.insert(address);
    }

    @Override
    public TbAddress selectById(Long id) {
        return tbAddressMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TbAddress> selectAddressByContact(String contact) {
        TbAddressExample example = new TbAddressExample();
        TbAddressExample.Criteria criteria = example.createCriteria();
        criteria.andContactEqualTo(contact);
        List<TbAddress> addressList = tbAddressMapper.selectByExample(example);
        return addressList;
    }
}
